import {
  getShareOptionRiskDataTwo,
  changeShareOptionRiskData,
  getShareOptionRiskDataFour,
} from '../../../../services/riskcontrol_service';

export default {
  namespace: 'riskoption',
  state: {
    riskDataTwo: {
      code: '',
      message: '',
      data: [],
    },
    riskDataFour: {
      code: '',
      message: '',
      data: [],
    },
  },

  effects: {
    *GetRiskDataTwo({ payload, callback }, { call, put }) {
      const response = yield call(getShareOptionRiskDataTwo, payload);
      if (typeof response === 'undefined') {
        return;
      }
      yield put({
        type: 'saveRiskDataTwo',
        payload: response,
      });
      if (callback) callback(response);
    },

    *GetRiskDataFour({ payload, callback }, { call, put }) {
      const response = yield call(getShareOptionRiskDataFour, payload);
      if (typeof response === 'undefined') {
        return;
      }
      yield put({
        type: 'saveRiskDataFour',
        payload: response,
      });
      if (callback) callback(response);
    },

    *ChangeRiskData({ payload, callback }, { call, put }) {
      const response = yield call(changeShareOptionRiskData, payload);
      if (typeof response === 'undefined') {
        return;
      }
      if (callback) callback(response);
    },
  },

  reducers: {
    saveRiskDataTwo(state, action) {
      return {
        ...state,
        riskDataTwo: action.payload,
      };
    },

    saveRiskDataFour(state, action) {
      return {
        ...state,
        riskDataFour: action.payload,
      };
    },
  },
};
